package masterjava.common.client.gxt.base.info;

import com.extjs.gxt.ui.client.core.XTemplate;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.util.Util;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import masterjava.common.client.gwt.settings.AppSettings;

/**
 * User: gkislin
 * Date: 8/4/11
 */
public class InfoPanel extends ContentPanel {
    private final XTemplate template;

    public static InfoPanel getInfoPanel(Enum contentKey) {
        InfoPanel panel = new InfoPanel(AppSettings.<String>get(contentKey));
        panel.applyTemplate(new BaseModelData(AppSettings.getSettings()));
        return panel;
    }

    public InfoPanel(String template) {
        this.template = XTemplate.create(template);
//        super(new FitLayout());
        setBodyStyleName("info-text");
    }

    public void applyTemplate(ModelData data) {
        removeAll();
        addText(template.applyTemplate(Util.getJsObject(data)));
        layout();
    }
}
